/* 单选框组件 - HarmonyOS设计指南实现 */

@import '../base/color.less';
@import '../base/font.less';
@import '../base/window.less';

/* 单选框变量 */
:root {
  --radio-size: calc(20 * var(--unit));
  --radio-size-small: calc(16 * var(--unit));
  --radio-size-large: calc(24 * var(--unit));
  --radio-dot-size: calc(8 * var(--unit));
  --radio-dot-size-small: calc(6 * var(--unit));
  --radio-dot-size-large: calc(10 * var(--unit));
  --radio-border-width: 2px;
  --radio-border-color: var(--color-comp-divider);
  --radio-border-color-checked: var(--color-brand);
  --radio-bg-color: transparent;
  --radio-dot-color: var(--color-brand);
  --radio-transition-duration: 0.2s;
  --radio-disabled-opacity: 0.5;
  --radio-gap: calc(8 * var(--unit));
}

/* 基础单选框样式 */
.radio {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.radio-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  
  &:checked + .radio-inner {
    border-color: var(--radio-border-color-checked);
    
    &::after {
      opacity: 1;
      transform: scale(1);
    }
  }
  
  &:disabled + .radio-inner {
    opacity: var(--radio-disabled-opacity);
    cursor: not-allowed;
  }
  
  &:disabled ~ .radio-text {
    opacity: var(--radio-disabled-opacity);
    cursor: not-allowed;
  }
  
  &:focus-visible + .radio-inner {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
  }
}

.radio-inner {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--radio-size);
  height: var(--radio-size);
  border: var(--radio-border-width) solid var(--radio-border-color);
  border-radius: 50%;
  background-color: var(--radio-bg-color);
  transition: all var(--radio-transition-duration) ease;
  flex-shrink: 0;
  
  &::after {
    content: '';
    position: absolute;
    width: var(--radio-dot-size);
    height: var(--radio-dot-size);
    border-radius: 50%;
    background-color: var(--radio-dot-color);
    opacity: 0;
    transform: scale(0);
    transition: all var(--radio-transition-duration) ease;
  }
}

.radio-text {
  margin-left: var(--radio-gap);
  font-size: var(--font-size-body-medium);
  color: var(--color-font-primary);
  line-height: 1.5;
}

/* 单选框尺寸 */
.radio-small,
.radio.small {
  .radio-inner {
    width: var(--radio-size-small);
    height: var(--radio-size-small);
    border-width: 1.5px;
    
    &::after {
      width: var(--radio-dot-size-small);
      height: var(--radio-dot-size-small);
    }
  }
  
  .radio-text {
    font-size: var(--font-size-body-small);
  }
}

.radio-large,
.radio.large {
  .radio-inner {
    width: var(--radio-size-large);
    height: var(--radio-size-large);
    border-width: 2.5px;
    
    &::after {
      width: var(--radio-dot-size-large);
      height: var(--radio-dot-size-large);
    }
  }
  
  .radio-text {
    font-size: var(--font-size-body-large);
  }
}

/* 单选框组 */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: calc(12 * var(--unit));
  
  &.radio-group-inline {
    flex-direction: row;
    flex-wrap: wrap;
    gap: calc(16 * var(--unit));
  }
}

/* 按钮样式单选框 */
.radio-button {
  display: inline-block;
  
  .radio-input {
    &:checked + .radio-button-inner {
      background-color: var(--color-brand);
      color: var(--color-font-on-primary);
      border-color: var(--color-brand);
    }
    
    &:focus-visible + .radio-button-inner {
      outline: 2px solid var(--color-brand);
      outline-offset: 2px;
    }
  }
  
  .radio-button-inner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: calc(64 * var(--unit));
    height: var(--button-height-medium);
    padding: 0 var(--button-padding-x-medium);
    border: 1px solid var(--color-comp-divider);
    border-radius: var(--button-border-radius);
    background-color: var(--color-comp-background-primary);
    color: var(--color-font-primary);
    font-size: var(--font-size-body-medium);
    transition: all var(--radio-transition-duration) ease;
    cursor: pointer;
    
    &:hover {
      border-color: var(--color-brand);
      color: var(--color-brand);
    }
  }
  
  &:has(.radio-input:disabled) .radio-button-inner:hover {
    border-color: var(--color-comp-divider);
    color: var(--color-font-primary);
    cursor: not-allowed;
  }
  
  .radio-text {
    margin: 0;
  }
}

.radio-group-button {
  display: inline-flex;
  gap: 0;
  
  .radio-button {
    .radio-button-inner {
      border-radius: 0;
      margin-left: -1px;
    }
    
    &:first-child .radio-button-inner {
      border-radius: var(--button-border-radius) 0 0 var(--button-border-radius);
      margin-left: 0;
    }
    
    &:last-child .radio-button-inner {
      border-radius: 0 var(--button-border-radius) var(--button-border-radius) 0;
    }
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .radio-inner {
    --radio-border-color: var(--color-comp-divider);
  }
  
  .radio-button .radio-button-inner {
    background-color: var(--color-comp-background-secondary);
    border-color: var(--color-comp-divider);
  }
}

